# $Id: Makefile.am 45982 2010-12-10 21:07:23Z richterm $
# Makefile template for the Alice HLT documentation
#
#**************************************************************************
#* This file is property of and copyright by the ALICE HLT Project        * 
#* ALICE Experiment at CERN, All rights reserved.                         *
#*                                                                        *
#* Permission to use, copy, modify and distribute this software and its   *
#* documentation strictly for non-commercial purposes is hereby granted   *
#* without fee, provided that the above copyright notice appears in all   *
#* copies and that both the copyright notice and this permission notice   *
#* appear in the supporting documentation. The authors make no claims     *
#* about the suitability of this software for any purpose. It is          *
#* provided "as is" without express or implied warranty.                  *
#**************************************************************************

EXTRA_DIST		= mainpage.c \
			  pics/HLT-AliRoot-Integration_overview.png \
			  pics/HLT-AliRoot-Integration_overview.eps \
			  pics/HLT-AliRoot-Integration_overview.png \
			  pics/HLT-AliRoot-Integration_overview.eps \
			  pics/PubSub_WrapperComponent.png

if BUILD_DOC
HTML			= html/index.html
MODULES			= 

if EN_HLT_TPC
MODULES			+= TPCLib
endif

if EN_HLT_RCU
MODULES			+= RCU
endif

if EN_HLT_PHOS
MODULES			+= PHOS
endif

if EN_HLT_TRD
MODULES			+= TRD
endif

if EN_HLT_MUON
MODULES			+= MUON
endif

if EN_HLT_COMP
MODULES			+= comp
endif

if EN_HLT_TRIGGER
MODULES			+= trigger
endif

if EN_HLT_GLOBAL
MODULES			+= global
endif

# if EN_HLT_ITS
# MODULES			+= ITS
# endif

#PDF			= latex/refman.pdf
TAGS			= $(PACKAGE).tags
else 
HTML			=
TAGS			= 
endif

if MONOLITHIC_DOC
RUN_MODULES		=
MAIN_MODULE		= doxymono.conf readme.c sample_readme.c module_group.c
MESSAGE			= monolithic
else
RUN_MODULES		= $(TAGS) $(MODULES)
MAIN_MODULE		= doxymain.conf
MESSAGE			= main
endif

DISTCLEANFILES		= doxy.log $(PACKAGE).tags

CLEANFILES		= $(MODULES:%=$(PACKAGE).%.tags) \
			  $(MODULES:%=%.conf)

SECTION_FILTER	= Directory File
CLASS_FILTER	= structAliHLTRawBuffer \
		  classAliHLTDataBuffer \
		  structAliHLTDataSegment \
		  TObject \
		  structAliHLTComponentEnvironment

%.png:%.fig
	fig2dev -Lpng $< 

all-local: $(RUN_MODULES) $(HTML) $(PDF)


clean-local: 
	rm -rf *~ html latex man readme.c sample_readme.c module_group.c $(MAIN_MODULE) $(TAGS)

readme.c: @top_srcdir@/README
	@cat $< | sed -e '/^=/s|=||g' -e '/^-/s|-||g'                     | \
	sed -e '/^+/d'                                                    | \
	sed -e '/^[0-9]. /s|^\([0-9]*\)\.|@section readme_\1 |'           | \
	sed -e '/^[0-9]*.[0-9] /s|^\([0-9]*\)\.\([0-9]*\)|@subsection readme_\1_\2 |' | \
	sed -e '/^  [-()\<a-zA-Z0-9.]/s|\([<>]\)|\\\1|g'                  | \
	sed -e '/^  [-()\<a-zA-Z0-9.]/s|\(.*\)|<tt>  \1</tt><br>|'        | \
	sed -e 's|\!\!\!\!|<b>|' -e 's|\!\!\!|</b>|'                      > $@_work
	@echo "/** @file $@"                                              > $@
	@echo '    @brief  autogenerated from README.'                   >> $@
	@echo '    @see  @ref readme                  */'                >> $@
	@echo '/** '                                                     >> $@
	@echo '    @page readme README'                                  >> $@
	@echo '    @section readme_toc TOC'                              >> $@
	@(for i in `cat $@_work | sed -e /@section/!d | cut -d ' ' -f 2` ; do \
	  echo "- @ref $$i" ; \
	done )                                                           >> $@
	@echo                                                            >> $@
	@cat $@_work                                                     >> $@
	@echo '*/'                                                       >> $@
	@rm $@_work

sample_readme.c: @top_srcdir@/SampleLib/README
	@echo "/** @file $@"                                              > $@
	@echo '    @brief  autogenerated from SampleLib/README.'         >> $@
	@echo '*/'                                                       >> $@
	@echo '/** '                                                     >> $@
	@echo '    @page sample_readme Creating a new Library'           >> $@
	@echo '<pre>'                                                    >> $@
	@cat $<                                                          | \
	sed -e 's|<|\&lt;|g' -e 's|>|\&gt;|g'                            >> $@
	@echo '</pre>'                                                   >> $@
	@echo '*/'                                                       >> $@

module_group.c: Makefile
	@echo "/** @file $@"                                              > $@
	@echo '    @brief  autogenerated from Makefile.'                 >> $@
	@echo '*/'                                                       >> $@
	@echo '/** @defgroup alihlt_modules HLT Detector Modules'        >> $@
	@echo                                                            >> $@
	@echo 'Available detector modules:'                              >> $@
	@$(foreach m, $(MODULES), echo "- @ref alihlt_`echo $(m) | tr '[:upper:]' '[:lower:]' | sed -e 's|lib||'`" >> $@;)
	@echo '*/'                                                       >> $@

doxymain.conf: doxygen.conf Makefile
	@t="$(foreach m, $(MODULES), @PACKAGE@.$(m).tags=$(m))"; \
	cat $< | sed -e "s|^\(TAGFILES[ ]*=\)|\1 $$t|" -e "/^WARN/s|=[ ]*NO|= YES|"> $@

doxymono.conf: doxygen.conf Makefile
	@t="$(foreach m, $(MODULES), @top_srcdir@/$(m))"; \
	cat $< | sed -e "s|^\(INPUT[ ]*=\)|\1 $$t|" -e "/^WARN/s|=[ ]*NO|= YES|"> $@

$(TAGS): doxygen.conf mainpage.c readme.c sample_readme.c module_group.c
	@echo creating main tag file ...
	$(DOXYGEN) $<  

$(HTML): $(MAIN_MODULE)
	@echo creating $(MESSAGE) documentation ...
	$(DOXYGEN) $<  

%.conf: doxymodule.conf Makefile
	@e=`find $(top_srcdir)/$(@:.conf=) -name configure.ac -exec dirname {} \;`; \
	e=`echo $$e | tr -d '\n'`; \
	cat $< | sed -e "s|@DOXYMODULE@|$(@:.conf=)|" -e "s|^\(EXCLUDE[ ]*=\)|\1 $$e|" > $@

html/%/index.html: %.conf
	@echo creating module ...
	$(DOXYGEN) $<

$(MODULES:%=html/%):
	@mkdir -p $@

$(MODULES): $(MODULES:%=html/%) $(MODULES:%=html/%/index.html)

$(MODULES:%=clean-%):
	rm -r html/$(patsubst clean-%,%,$(@))

tar-ball:$(HTML)
	if test -f html/index.html ; then \
	  mv html $(PACKAGE) ;	\
	  tar -czvf ../$(PACKAGE)-$(VERSION)-doc.tar.gz $(PACKAGE) ; \
	  mv $(PACKAGE) html ; fi 

$(PDF:.pdf=.tex_): $(PDF:.pdf=.tex)
	cat $< \
	$(foreach i, $(SECTION_FILTER), \
	 | sed -e '/$i Documentation/,/section/ { /input/d}' \
	 | sed -e '/$i Documentation/ d' \
	) \
	$(foreach i, $(CLASS_FILTER), \
	 | sed -e '/input{$i}/d' \
	) \
	> $@
	cp -a $@ $<

$(PDF): latex/Makefile $(PDF:.pdf=.tex_)
	@(cd latex && $(MAKE))
#
# EOF
#
